#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/types.h>  
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "client_function.h"

#define PORT 6666
#define SERVERIP "192.168.43.58"
#define PERROR(a) do{perror("a");return -1;}while(0)  

int sockfd = -1;

int main()
{
    //创建套接字   流式
    sockfd=socket(AF_INET,SOCK_STREAM,0);
    if(sockfd == -1)
    {
        PERROR(socket);
    }
    printf("socket is already ok!\n");
    
    //封装sockaddr_in结构体
    struct sockaddr_in ser_addr;
    ser_addr.sin_family = AF_INET;
    ser_addr.sin_port = htons(PORT);
    ser_addr.sin_addr.s_addr = inet_addr(SERVERIP);
	
    //连接服务器
    if(-1 == connect(sockfd,(struct sockaddr*)&ser_addr,sizeof(struct sockaddr)))
    {
        PERROR(connect);
    }
    printf("connect server success\n");

    while(1)
    {
        client_interface1();
    }

    if(-1 == close(socket))
    {
        PERROR(close);
    }
    return 0;
}
